#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <aclconio.h>
#include <define.h>
#include <transact.h>
#include <tran.h>
#include <gds.h>
#include <sizes.h>
#include "ConfProto.h"
#include "tblutil.h"
#include <\SOFTPAY\Ver30\source\include\sizes.h>
#include <\SOFTPAY\Ver30\HostSrc\citisrc\citiids.h>
#include <\SOFTPAY\Ver30\HostSrc\cpacsrc\cpacids.h>
#include <confio.h>

#include <\SOFTPAY\Ver30\source\include\MST.h>



static void *storeFromStruct;

static int recordNum;
void registerMST(void *ptr)
{
	 storeFromStruct = ptr;
}

void *dealWithAddressBoundary(void*address);
int	inLoadMSTRecFromStruct (int inRecNumber, void *vdStruct)
{
	int inRet;
	char* tmp = (char*)vdStruct;

	registerMST(vdStruct);
	vdStruct = dealWithAddressBoundary(vdStruct);
	inRet = inLoadConfRec(MST_FILENAME, SIZE_MST_REC, inRecNumber, vdStruct);

	recordNum = inRecNumber;
	return inRet;
}

void vdRestoreMSTRecFromStruct(void *vdStruct)
{
	registerMST(vdStruct);
	vdStruct = dealWithAddressBoundary(vdStruct);
	memcpy((char *) pvdGetMSTRec(), vdStruct, SIZE_MST_REC);

}

void vdCopyMSTRecFromStruct(void *vdStruct)
{
	registerMST(vdStruct);
	vdStruct = dealWithAddressBoundary(vdStruct);
		memcpy(vdStruct, (char *) pvdGetMSTRec(), SIZE_MST_REC);

}

int	inSaveMSTRecFromStruct (int inRecNumber,  void *vdStruct)
{
	int inRet;

	registerMST(vdStruct);
	vdStruct = dealWithAddressBoundary(vdStruct);
	inRet = inSaveConfRec(MST_FILENAME, SIZE_MST_REC, inRecNumber, (char *) vdStruct);

	return inRet;
}

int	inUpdateMSTRecFromStruct (void *vdStruct)
{
	int inRet;

	registerMST(vdStruct);
	vdStruct = dealWithAddressBoundary(vdStruct);
	inRet = inSaveConfRec(MST_FILENAME, SIZE_MST_REC, recordNum, (char *) vdStruct);

	return inRet;
}

short shGetMaxBannersFromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return shGetMaxBanners();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((MST_REC*)vdStruct)->shMaxBanners;
}

void vdSetMaxBannersFromStruct(short shMaxBanners, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetMaxBanners(shMaxBanners);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	((MST_REC*)vdStruct)->shMaxBanners = shMaxBanners;
}

VS_BOOL fGetVCSessionFromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return fGetVCSession();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((MST_REC*)vdStruct)->fVCSession;
}

void vdSetVCSessionFromStruct(VS_BOOL fVCSession, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetVCSession(fVCSession);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	((MST_REC*)vdStruct)->fVCSession = fVCSession;
}

